home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Environments / TurPasDBTlbx / TP-Database Toolbox / SetConst source / ConstUser.unit next >
Encoding:
Text File  |  1987-12-11  |  18.4 KB  |  765 lines  |  [TEXT/TPAS]

  1. (*********************************************************************)
  2. (*                  Turbo Pascal Database Toolbox                    *)
  3. (*                       For the Macintosh                           *)
  4. (*            Copyright (C) 1987 Borland International               *)
  5. (*                     Toolbox version: 1.0                          *)
  6. (*                                                                   *)
  7. (*            SetConst User Interface and Calculation Unit.          *)
  8. (*                                                                   *)
  9. (*********************************************************************)
  10. unit ConstUser(121);
  11. interface
  12. {$U-}
  13. uses MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntF, PasInOut;
  14.  
  15. var
  16.   DefaultMaxRecSize,
  17.   DefaultMaxKey : integer;
  18.   MaxMemory : LongInt;
  19.   
  20.   AlwaysUseDefaults,
  21.   ShowCompileInfo : boolean;
  22.  
  23. procedure InitSetConst;
  24.  
  25. function UseDefaults : boolean;
  26.  
  27. procedure InitWorkSheet;
  28.     
  29. procedure SetConstants;
  30.  
  31. procedure FinishUp;
  32.  
  33. implementation
  34.  
  35. procedure HighLiteButton(CurDialog : DialogPtr;
  36.                        ButtonNum : integer;
  37.                        UseBlack : boolean);
  38. const
  39.   Gap = 4;
  40.  
  41. var
  42.   SavePort : GrafPtr;
  43.   SavePen : PenState;                        
  44.   IHandle  : Handle;
  45.   Itype : integer;
  46.   IRect : rect;
  47.  
  48. begin
  49.   GetPort(SavePort);
  50.   SetPort(CurDialog);
  51.   GetPenState(SavePen);
  52.   GetDItem(CurDialog, ButtonNum, IType, IHandle, IRect);
  53.   if UseBlack then
  54.     PenPat(Black)
  55.   else
  56.     PenPat(White);
  57.   PenSize(3, 3);
  58.   InsetRect(IRect, -Gap, -Gap);
  59.   FrameRoundRect(IRect, 4 * Gap, 4 * Gap);
  60.   SetPort(SavePort);
  61.   SetPenState(SavePen);
  62. end; { HighLiteButton }
  63.  
  64.  
  65. type
  66.   FileBuf = packed array[0..MaxInt] of char;
  67.   FileBufferPtr = ^FileBuf;
  68.   FileRec = record    { Internal format of a Turbo file variable }
  69.               FInpFlag : boolean;
  70.               FOutFlag : boolean;
  71.               FRefNum : integer;  { Reference number is used for }
  72.               FVRefNum : integer;       { Mac File Manager calls }
  73.               FBufSize : integer;
  74.               FBufPos : integer;
  75.               FBufEnd : integer;
  76.               FBuffer : FileBufferPtr;
  77.               FInOutProc : ProcPtr;
  78.             end;
  79. var
  80.   Str : String;
  81.   StrVal : Text;
  82.       
  83. function StrKludge(var F : FileRec) : integer;
  84. var
  85.   P : integer;
  86. begin
  87.   StrKludge := 0;
  88.   with F do
  89.   begin
  90.     if FOutFlag then
  91.     begin
  92.       Str := '';
  93.       for P := 0 to FBufPos - 1 do
  94.         Str := Str + FBuffer^[P];
  95.       FBufPos := 0;  
  96.     end;
  97.   end;
  98. end; { StrKludge }
  99.  
  100.  
  101. procedure InitStr;
  102. begin
  103.   Device('Str:', @StrKludge);
  104.   Rewrite(StrVal,'Str:');
  105. end;
  106.  
  107. const
  108.   MaxRec = 4;
  109.   PageStack = 6;
  110.   DSearch = 12;
  111. var
  112.   ItemHandles : Array[MaxRec..DSearch] of handle;
  113.  
  114. type
  115.   DBoxParameters = record
  116.                      case integer of
  117.                      0 : ( MaxRecs        : real;
  118.                            PageSize       : real;
  119.                            PageStackSize  : real;
  120.                            
  121.                            DxSize         : real;
  122.                            IxSize         : real;
  123.                            StackMem       : real;
  124.                            
  125.                            MaxSearch      : real;
  126.                            MemSearch      : real;
  127.                            DiskSearch     : real;
  128.                            
  129.                            MaxDataRecSize : integer;
  130.                            MaxKeyLen      : integer;
  131.                            Order          : integer;
  132.                            MaxHeight      : integer
  133.                          );
  134.                      1 : ( ItemIndex : array[MaxRec ..DSearch] of real;
  135.                            MaxData        : integer;
  136.                            MaxKey         : integer;
  137.                            TOrder         : integer;
  138.                            TMaxHeight     : integer
  139.                          )
  140.                    end;
  141. var
  142.   DBoxParams :  DBoxParameters;
  143.    
  144. const
  145.   DefaultPageSize       =  24;
  146.   DefaultPageStackSize  =  20;
  147.   DefaultOrder          =  10;
  148.   DefaultMaxHeight      =   5;
  149.   DefaultMaxRecs        =  1000;
  150.  
  151. procedure StoreDefaults(var DBoxParams :  DBoxParameters);
  152.  
  153. function CheckResults(MaxKeyLen, PageSize, PageStackSize : real;
  154.                       var StackMem : real) : real;
  155. const
  156.   Density        = 0.75;
  157.  
  158. var
  159.   M    : real;
  160.   Temp : Real;
  161.   I    : Integer;
  162.   NumRecs : real;
  163.  
  164.   PerPage,
  165.   MaxSearch,
  166.   MemSearch,
  167.   IrSize, 
  168.   TotalPages : real;
  169.     
  170. begin
  171.   CheckResults := 0;
  172.   IrSize:=(MaxKeyLen+9) * PageSize + 6;
  173.   StackMem := IrSize * PageStackSize;
  174.   if StackMem > MaxMemory then
  175.     Exit;
  176.   PerPage:=PageSize*Density;
  177.   NumRecs := 1000;
  178.   MaxSearch := Ln(NumRecs)/Ln(PerPage);
  179.   TotalPages:=Int(NumRecs/PerPage+1.0);
  180.   Temp:=1.0;
  181.   M:=PerPage;
  182.   I:=1;
  183.   while Temp+M<PageStackSize do
  184.   begin
  185.     Temp:=Temp + M;
  186.     I:= succ(I);
  187.     M:=Exp(Ln(PerPage) * I);
  188.   End;
  189.   If Temp + M > TotalPages 
  190.    then M:= TotalPages - Temp + 1;
  191.   MemSearch:= I + (PageStackSize-Temp)/M;
  192.   MemSearch := (MemSearch / MaxSearch);
  193.   if MemSearch > 1 then
  194.     MemSearch := 0.990;
  195.   CheckResults := MemSearch / (MaxSearch * 100);
  196. end;  { CheckResults }
  197.  
  198. procedure CalcDefaults(var DBoxParams : DBoxParameters);
  199. const
  200.   Density        = 0.75;
  201.  
  202. var
  203.   BestResult,
  204.   CurResult,
  205.   CurPSize,
  206.   CurPStack,
  207.   CurStackMem : real;
  208.  
  209. begin
  210.   with DBoxParams do
  211.   begin
  212.     CurPSize := 4;
  213.     CurPStack := 3;
  214.     CurStackMem := 0;
  215.     BestResult := 0;
  216.     while (CurStackMem <= MaxMemory) do
  217.     begin
  218.       CurResult := CheckResults(MaxKeyLen, CurPSize, CurPStack, CurStackMem);
  219.       if CurResult > BestResult then
  220.       begin
  221.         BestResult := CurResult;
  222.         PageSize := CurPSize;
  223.         PageStackSize := CurPStack;
  224.       end;
  225.       CurPStack := CurPStack + 1;
  226.       CurPSize := CurPSize + 2;
  227.     end;
  228.   end;
  229. end; { CalcDefaults }
  230.  
  231. begin
  232.   with DBoxParams do
  233.   begin
  234.     MaxDataRecSize := DefaultMaxRecSize;
  235.     MaxKeyLen := DefaultMaxKey;
  236.     PageSize := DefaultPageSize;
  237.     PageStackSize := DefaultPageStackSize;
  238.     Order := DefaultOrder;
  239.     MaxHeight := DefaultMaxHeight;
  240.     MaxRecs := DefaultMaxRecs;
  241.   end;
  242.   CalcDefaults(DBoxParams);
  243. end; { StoreDefaults }
  244.  
  245.   
  246. const
  247.   ParamDialogId = 24135;
  248. var
  249.   ParamDialog : DialogPtr;
  250.  
  251. procedure SetParams(var ParamDialog : DialogPtr;
  252.                         var DBoxParams : DBoxParameters);
  253. var
  254.   index : integer;
  255.  
  256. begin
  257.   with DBoxParams do
  258.     for index := MaxRec to PageStack do
  259.     begin
  260.       Write(StrVal, ItemIndex[Index]:1:0);
  261.       SetIText(ItemHandles[Index], Str);
  262.     end;
  263. end;
  264.  
  265.  
  266. procedure SetUpDefaults(var ParamDialog : DialogPtr;
  267.                         var DBoxParams : DBoxParameters);
  268. var
  269.   MaxRecStr,
  270.   MaxKeyStr : string;
  271.  
  272. begin
  273.   with DBoxParams do
  274.   begin
  275.     Write(StrVal, MaxDataRecSize:4);     MaxRecStr := Str;
  276.     Write(StrVal, MaxKeyLen:4);          MaxKeyStr := Str;
  277.     ParamText(MaxRecStr, MaxKeyStr,'','');
  278.     SetParams(ParamDialog, DBoxParams);
  279.   end;
  280. end; { SetUpDefaults }
  281.   
  282. procedure SetUpDialog(var ParamDialog : DialogPtr;
  283.                       var DBoxParams : DBoxParameters);
  284. const
  285.   CalcButton = 1;                     
  286. var
  287.   Item : integer;
  288.   ItemType : integer;
  289.   box : rect;
  290.  
  291. begin
  292.   ParamDialog := GetNewDialog(ParamDialogId,NIL,pointer(-1));
  293.   for Item := MaxRec to DSearch do
  294.     GetDItem(ParamDialog, Item, ItemType, ItemHandles[Item], box);
  295.   SetUpDefaults(ParamDialog, DBoxParams);
  296.   HighliteButton(ParamDialog, CalcButton, true);
  297.   SelIText(ParamDialog, MaxRec, 0, MaxInt);
  298. end; { SetUpDialog }
  299.  
  300.  
  301. var
  302.   PerPage        : real;
  303.   TotalPages     : real;
  304.   IrSize         : real;
  305.  
  306. procedure DoCalculations(var DBoxParams : DBoxParameters);
  307. const
  308.   Density        = 0.75;
  309.  
  310. var
  311.   M    : real;
  312.   Temp : Real;
  313.   I    : Integer;
  314.  
  315. procedure SetMaxHeight;
  316. var
  317.   Quarters, 
  318.   MaxMaxHeight : integer;
  319.    
  320. begin
  321.   MaxMaxHeight := 0;
  322.   with DBoxParams do
  323.   begin
  324.     for Quarters := 2 to 4 do
  325.     begin
  326.       PerPage:= PageSize * (Quarters * 0.25);
  327.       MaxSearch := Ln(MaxRecs)/Ln(PerPage);
  328.       MaxHeight:=Trunc(MaxSearch+1.0);
  329.       if MaxHeight > MaxMaxHeight then
  330.         MaxMaxHeight := MaxHeight; 
  331.     end;   
  332.     MaxHeight := MaxMaxHeight;
  333.   end;
  334. end; { SetMaxHeight }
  335.     
  336. begin
  337.   with DBoxParams do
  338.   begin
  339.     SetMaxHeight;
  340.     PerPage:=PageSize * Density;
  341.     MaxSearch := Ln(MaxRecs)/Ln(PerPage);    
  342.     Order:= Trunc(PageSize / 2.0);    
  343.     TotalPages:=Int(MaxRecs/PerPage+1.0);
  344.     Temp:=1.0;
  345.     M:=PerPage;
  346.     I:=1;
  347.     while Temp+M<PageStackSize do
  348.     begin
  349.       Temp:=Temp + M;
  350.       I:=I + 1;
  351.       M:=Exp(Ln(PerPage) * I);
  352.     End;
  353.     If Temp+M>TotalPages Then M:=TotalPages-Temp+1;
  354.     MemSearch:=I+(PageStackSize-Temp)/M;
  355.     DiskSearch:=MaxSearch-MemSearch;
  356.     IrSize:=(MaxKeyLen+9) * PageSize + 6;
  357.     IxSize:=IrSize*TotalPages;
  358.     DxSize:=MaxDataRecSize*(MaxRecs+1);
  359.     StackMem:= IrSize * PageStackSize;
  360.     MemSearch := (MemSearch / MaxSearch) * 100.0;
  361.     DiskSearch := (DiskSearch / MaxSearch)  * 100.0;
  362.     if MemSearch > 100.0 then
  363.      begin
  364.        MemSearch := 99.00;
  365.        DiskSearch := 1.00;
  366.      end;
  367.   end;
  368. end;  { DoCalculations }
  369.  
  370.   
  371. procedure ParamToDialog(var DBoxParams : DBoxParameters;
  372.                         var ParamDialog : DialogPtr);
  373. const
  374.   DataFItem = 7;
  375.   IndexFItem = 8;
  376.   StackMemItem = 9;
  377.   MaxSearchItem = 10;
  378.   MemSearchItem = 11;
  379. var
  380.   Index : integer;
  381.                             
  382. begin
  383.   DoCalculations(DBoxParams);
  384.   with DBoxParams do
  385.     for Index := DataFItem to DSearch do
  386.     begin
  387.       case Index of 
  388.         DataFItem     : Write(StrVal, DxSize:14:0);
  389.         IndexFItem    : Write(StrVal, IxSize:15:0);
  390.         StackMemItem  : Write(StrVal, StackMem:10:0);
  391.         MaxSearchItem : Write(StrVal, MaxSearch:4:2);
  392.         MemSearchItem, 
  393.         DSearch       : begin
  394.                           if Index = MemSearchItem then
  395.                             Write(StrVal, MemSearch:5:2)
  396.                           else
  397.                             Write(StrVal, DiskSearch:5:2);
  398.                           Str := Str + ' %'
  399.                         end;
  400.       end;
  401.       SetItext(ItemHandles[Index], Str);
  402.     end;
  403. end; { ParamToDialog }
  404.  
  405.  
  406. procedure DialogToParam(var ParamDialog : DialogPtr;
  407.                         var DBoxParams : DBoxParameters);
  408. var                        
  409.   S : string;
  410.   Index : integer;
  411.   L : LongInt;
  412.   
  413. begin
  414.   with DBoxParams do
  415.     for index := MaxRec to PageStack do
  416.     begin
  417.       GetIText(ItemHandles[Index], S);
  418.       StringToNum(S, L);
  419.       ItemIndex[Index] := L;
  420.     end;
  421. end; { DialogToParam }
  422.  
  423. procedure SoundAlert(ResId : LongInt);
  424. var
  425.   Temp : integer;
  426. begin
  427.   HighliteButton(ParamDialog, 1, false);
  428.   Temp := StopAlert(ResId, nil);
  429.   HighliteButton(ParamDialog, 1, true);
  430. end; { SoundAlert }
  431.  
  432. function OkStackMem(DBoxParams : DBoxParameters ) : boolean;
  433. var
  434.   Legal : boolean;
  435. begin
  436.   with DBoxParams do
  437.   begin 
  438.     IrSize := (MaxKeyLen + 9) * PageSize+6;
  439.     StackMem := IrSize * PageStackSize;
  440.     Legal := StackMem <= MaxInt;
  441.     if not Legal then
  442.       SoundAlert(20147);
  443.   end;
  444.   OkStackMem := Legal; 
  445. end;
  446.  
  447. function LegalValues(DBoxParams : DBoxParameters;
  448.                      ParamDialog : DialogPtr) : boolean;
  449. const
  450.   PageS = 5;                    
  451. var
  452.   Legal : boolean;
  453.   Index, temp : integer;
  454. begin
  455.   Legal := true;
  456.   DialogToParam(ParamDialog, DBoxParams);
  457.   index := MaxRec;
  458.   with DBoxParams do
  459.     while (Index <= PageStack) and Legal do
  460.     begin
  461.       case Index of 
  462.         MaxRec : begin
  463.                    Legal := ItemIndex[MaxRec] > 0;
  464.                    if not Legal then
  465.                      SoundAlert(10130);
  466.                  end;
  467.         PageS : begin
  468.                   Legal :=  (ItemIndex[PageS] >= 4)
  469.                             and (ItemIndex[PageS] <= 254)
  470.                             and (not odd(trunc(ItemIndex[PageS])));
  471.                   if not Legal then
  472.                     SoundAlert(24839);
  473.                 end;
  474.         PageStack : begin
  475.                       Legal := (ItemIndex[PageStack] >= 3)
  476.                                and (ItemIndex[PageStack] <= 254);
  477.                       if not Legal then
  478.                         SoundAlert(31164);
  479.                     end;
  480.           
  481.       end;
  482.       Index := succ(Index);
  483.     end;
  484.   if Legal then
  485.     Legal := OkStackMem(DBoxParams);
  486.   LegalValues := Legal;
  487. end;
  488.  
  489. var
  490.   ClockCursor:   CursHandle; {handle to the waiting watch cursor}
  491.  
  492. const
  493.   OKButton = 1;
  494.   DialogId = 11451;
  495.   
  496. procedure ClickButton(D : DialogPtr; ItemNo : integer);
  497. var
  498.   IType : integer;
  499.   ButtonHandle : ControlHandle;
  500.   Box : rect;
  501.   L : LongInt;
  502.    
  503. begin
  504.   ObscureCursor;
  505.   GetDItem(D, ItemNo, IType, Handle(ButtonHandle), box);
  506.   HiliteControl(ButtonHandle, 253);
  507.   Delay(5, L);
  508.   HiliteControl(ButtonHandle, 0);
  509. end; { ClickButton }
  510.  
  511. function NumFilter(NumDialog : DialogPtr; 
  512.                    var Event : EventRecord;
  513.                    var ItemHit : integer) : boolean;
  514. const
  515.   CR = #13;
  516.   Enter = #03;
  517.   BS = #8; { Backspace key }
  518.   Tab = ^I; { Tab key }
  519.                   
  520. var
  521.   KeyCh : char;
  522.                      
  523. begin
  524.   NumFilter := false;
  525.   if Event.what = KeyDown then
  526.   begin
  527.     KeyCh := Chr(Event.Message and charCodeMask);
  528.     if (KeyCh = CR) or (KeyCh = Enter) then
  529.     begin
  530.       NumFilter := true;
  531.       ItemHit := 1;
  532.       ClickButton(NumDialog, 1);
  533.     end
  534.     else
  535.     begin
  536.       if not (KeyCh in ['0'..'9']) 
  537.          and not (KeyCh in [BS, Tab]) then
  538.       begin
  539.         Event.what := nullEvent;
  540.         NumFilter := true;
  541.         ItemHit := 0;
  542.       end;  
  543.     end;
  544.   end;
  545. end; { NumFilter }
  546.  
  547. procedure SetConstants;
  548. const
  549.   CalcButton = 1;
  550.   QuitButton = 2;
  551.   DefaultsButton = 3;
  552. var
  553.   ItemHit,
  554.   LastItem : integer;
  555.  
  556. begin
  557.   SetUpDialog(ParamDialog, DBoxParams);
  558.   LastItem := MaxRec;
  559.   ParamToDialog(DBoxParams, ParamDialog);
  560.   with DBoxParams do
  561.   begin
  562.     repeat
  563.       ModalDialog(@NumFilter,ItemHit);
  564.       case ItemHit of
  565.         QuitButton : ;
  566.         CalcButton,
  567.         DefaultsButton : begin
  568.                            if ItemHit = CalcButton then
  569.                            begin
  570.                              if LegalValues(DBoxParams,ParamDialog) then
  571.                                DialogToParam(ParamDialog, DBoxParams);
  572.                            end
  573.                            else
  574.                            begin
  575.                              SetCursor(ClockCursor^^);
  576.                              StoreDefaults(DBoxParams);
  577.                              SetParams(ParamDialog, DBoxParams);
  578.                              InitCursor;
  579.                            end;
  580.                            ParamToDialog(DBoxParams, ParamDialog);
  581.                            SelIText(ParamDialog, LastItem, 0, MaxInt);
  582.                            ItemHit := LastItem;          
  583.                          end;
  584.         MaxRec..PageStack : if (ItemHit <> LastItem) and
  585.                                (LastItem <> 0) then
  586.                               SelIText(ParamDialog, ItemHit, 0, MaxInt);
  587.       end; { case }
  588.       LastItem := ItemHit;
  589.     until ItemHit = QuitButton;
  590.     DisposDialog(ParamDialog); 
  591.   end;
  592. end; { SetConstants }
  593.  
  594. function CreateFile(var F : text;
  595.                         var FN : string;
  596.                         Prompt : String) : boolean;
  597. var
  598.   Ok : boolean;
  599.   Start : point;
  600.   reply : SFReply;
  601.     
  602. begin
  603.   CreateFile := false;
  604.   with Start Do
  605.   begin
  606.     v := 90;
  607.     h := 80;
  608.   end;
  609.   SFPutFile(Start, Prompt, FN, NIL, reply);
  610.   with Reply do
  611.   begin
  612.     Ok := good;
  613.     if Ok then
  614.       Ok := SetVol(nil, VRefNum) = NoErr;
  615.     if Ok then
  616.     begin
  617.       {$I-}
  618.       Rewrite(F, FName);
  619.       {$I+}
  620.       Ok := IOResult = 0;
  621.       if Ok then
  622.         FN := FName;
  623.     end;
  624.   end;
  625.   CreateFile := Ok;
  626. end; { CreateFile }
  627.  
  628. procedure SaveConstants(var Results : text;
  629.                         DBoxParams : DBoxParameters);
  630. const
  631.   Tab = 2;                      
  632. begin
  633.   Writeln(Results, '{ Turbo Access constants }');
  634.   Writeln(Results , 'const');
  635.   with DBoxParams do
  636.   begin
  637.     Writeln(Results, ' ':Tab, 'MaxDataRecSize = ', MaxDataRecSize, ';');
  638.     Writeln(Results, ' ':Tab, 'MaxKeyLen = ', MaxKeyLen, ';');
  639.     Writeln(Results, ' ':Tab, 'PageSize = ', PageSize:1:0, ';');
  640.     Writeln(Results, ' ':Tab, 'PageStackSize = ', PageStackSize:1:0, ';');
  641.     Writeln(Results, ' ':Tab, 'Order = ', Order, ';');
  642.     Writeln(Results, ' ':Tab, 'MaxHeight = ', MaxHeight, ';');
  643.   end;
  644.   Close(Results);
  645. end; { SaveConstants }   
  646.                     
  647. function UseDefaults{ : boolean};
  648. const
  649.   Default = 1;
  650.   Experiment = 2;
  651.   
  652. var
  653.   DefaultDialog : DialogPtr;
  654.   ItemHit : integer;
  655.   IType : integer;
  656.   IHandle : Handle;
  657.   IRect : Rect;
  658.  
  659. begin
  660.   DefaultDialog := GetNewDialog(16882,NIL,pointer(-1));
  661.   HighliteButton(DefaultDialog, Default, true);
  662.   repeat
  663.     ModalDialog(nil,ItemHit);
  664.   until ItemHit in [Default, Experiment];
  665.   UseDefaults := ItemHit = Default;
  666.   DisposDialog(DefaultDialog); 
  667.   DoCalculations(DBoxParams);
  668. end;  { UseDefaults }
  669.   
  670. procedure CompileInfo(ResultFile : string);
  671. const
  672.   OkButton = 1;
  673. var
  674.   InfoDialog : DialogPtr;
  675.   ItemHit : integer;
  676.  
  677. begin
  678.   InfoDialog := GetNewDialog(27861, NIL,pointer(-1));
  679.   ParamText(ResultFile, '','','');
  680.   repeat
  681.     ModalDialog(nil, ItemHit);
  682.   until ItemHit = OkButton;
  683. end; { CompileInfo }
  684.  
  685. procedure FinishUp;
  686. const
  687.   Prompt = 'Save constants to:';
  688. var
  689.   Results : text;
  690.   NameHandle : Handle;
  691.   FileName,
  692.   TempName : String;
  693.   S : StringHandle;
  694.   M : MenuHandle;
  695.   
  696. begin
  697.   ClearMenuBar;
  698.   DrawMenuBar;
  699.   NameHandle := GetResource('STR ', 1000);
  700.   if NameHandle <> nil then
  701.     FileName := StringHandle(NameHandle)^^
  702.   else
  703.      FileName := '';
  704.   TempName := FileName;
  705.   if CreateFile(Results, FileName, Prompt) then
  706.   begin
  707.     SaveConstants(Results, DBoxParams);
  708.     if ShowCompileInfo then
  709.       CompileInfo(FileName);
  710.     if TempName <> FileName then
  711.     begin
  712.       LoadResource(NameHandle);
  713.       HNoPurge(NameHandle);
  714.       SetHandleSize(NameHandle, succ(Length(FileName)));
  715.       StringHandle(NameHandle)^^ := FileName;
  716.       ChangedResource(NameHandle);
  717.       WriteResource(NameHandle);
  718.       HPurge(NameHandle);
  719.     end;
  720.   end;
  721. end; { FinishUp }
  722.  
  723.  
  724. procedure InitSetConst;
  725. var
  726.   S : StringHandle;
  727.   M : MenuHandle;
  728.  
  729. begin
  730.   InitGraf(@thePort);
  731.   MoreMasters;
  732.   ClockCursor := GetCursor(watchCursor);
  733.   HLock(Handle(ClockCursor));
  734.     {show the watch while we wait for inits & setups to finish}
  735.   SetCursor(ClockCursor^^);
  736.  
  737.   InitFonts;
  738.   InitWindows;
  739.   TEInit;
  740.   InitDialogs(NIL);
  741.   InitMenus;
  742.  
  743.   FlushEvents(EveryEvent, 0);
  744.   S := GetString(1002);
  745.   M := NewMenu(100, S^^);
  746.   InsertMenu(M, 0);
  747.   DrawMenuBar;
  748.   StoreDefaults(DBoxParams);
  749.   InitCursor;           {ready to go, so show the Arrow cursor}
  750. end; { InitSetConst }
  751.  
  752. procedure InitWorkSheet;
  753. var
  754.   M : MenuHandle;
  755.   S : StringHandle;
  756. begin
  757.   ClearMenuBar;
  758.   S := GetString(1001);
  759.   M := NewMenu(100, S^^);
  760.   InsertMenu(M, 0);
  761.   DrawMenuBar;
  762.   InitStr;
  763. end; { InitWorkSheet }
  764.  
  765. end.